Class 6 Exam  >  Class 6 Questions  >  What is the output of the following program?#... Start Learning for Free
What is the output of the following program?
#include<stdio.h>
int c[10] = {1,2,3,4,5,6,7,8,9,10};   
main()
{
   int a, b=0;
   for(a=0;a<10;++a)
      if(c[a]%2 == 1)
         b+=c[a];
   printf("%d", b);
}
  • a)
    20
  • b)
    24
  • c)
    25
  • d)
    30
Correct answer is option 'C'. Can you explain this answer?
Most Upvoted Answer
What is the output of the following program?#include<stdio.h>int...

Explanation:

Initial Array:
- The initial array c contains values from 1 to 10.

Loop:
- The for loop iterates through each element of the array c.
- It checks if the current element is odd (since it checks if c[a] % 2 == 1).
- If the element is odd, it adds the element to the variable b.

Calculations:
- In the array c, the odd numbers are 1, 3, 5, 7, 9.
- Adding these odd numbers (1 + 3 + 5 + 7 + 9) gives the result 25.

Output:
- The final result stored in variable b is 25.
- Therefore, when the program is executed, it will output 25.
Free Test
Community Answer
What is the output of the following program?#include<stdio.h>int...
Condition if(c[a]%2 == 1) forces only odd numbers to add in the sum.
Explore Courses for Class 6 exam
Question Description
What is the output of the following program?#include<stdio.h>int c[10] = {1,2,3,4,5,6,7,8,9,10}; main(){ int a, b=0; for(a=0;a<10;++a) if(c[a]%2 == 1) b+=c[a]; printf("%d", b);}a)20b)24c)25d)30Correct answer is option 'C'. Can you explain this answer? for Class 6 2025 is part of Class 6 preparation. The Question and answers have been prepared according to the Class 6 exam syllabus. Information about What is the output of the following program?#include<stdio.h>int c[10] = {1,2,3,4,5,6,7,8,9,10}; main(){ int a, b=0; for(a=0;a<10;++a) if(c[a]%2 == 1) b+=c[a]; printf("%d", b);}a)20b)24c)25d)30Correct answer is option 'C'. Can you explain this answer? covers all topics & solutions for Class 6 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for What is the output of the following program?#include<stdio.h>int c[10] = {1,2,3,4,5,6,7,8,9,10}; main(){ int a, b=0; for(a=0;a<10;++a) if(c[a]%2 == 1) b+=c[a]; printf("%d", b);}a)20b)24c)25d)30Correct answer is option 'C'. Can you explain this answer?.
Solutions for What is the output of the following program?#include<stdio.h>int c[10] = {1,2,3,4,5,6,7,8,9,10}; main(){ int a, b=0; for(a=0;a<10;++a) if(c[a]%2 == 1) b+=c[a]; printf("%d", b);}a)20b)24c)25d)30Correct answer is option 'C'. Can you explain this answer? in English & in Hindi are available as part of our courses for Class 6. Download more important topics, notes, lectures and mock test series for Class 6 Exam by signing up for free.
Here you can find the meaning of What is the output of the following program?#include<stdio.h>int c[10] = {1,2,3,4,5,6,7,8,9,10}; main(){ int a, b=0; for(a=0;a<10;++a) if(c[a]%2 == 1) b+=c[a]; printf("%d", b);}a)20b)24c)25d)30Correct answer is option 'C'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of What is the output of the following program?#include<stdio.h>int c[10] = {1,2,3,4,5,6,7,8,9,10}; main(){ int a, b=0; for(a=0;a<10;++a) if(c[a]%2 == 1) b+=c[a]; printf("%d", b);}a)20b)24c)25d)30Correct answer is option 'C'. Can you explain this answer?, a detailed solution for What is the output of the following program?#include<stdio.h>int c[10] = {1,2,3,4,5,6,7,8,9,10}; main(){ int a, b=0; for(a=0;a<10;++a) if(c[a]%2 == 1) b+=c[a]; printf("%d", b);}a)20b)24c)25d)30Correct answer is option 'C'. Can you explain this answer? has been provided alongside types of What is the output of the following program?#include<stdio.h>int c[10] = {1,2,3,4,5,6,7,8,9,10}; main(){ int a, b=0; for(a=0;a<10;++a) if(c[a]%2 == 1) b+=c[a]; printf("%d", b);}a)20b)24c)25d)30Correct answer is option 'C'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice What is the output of the following program?#include<stdio.h>int c[10] = {1,2,3,4,5,6,7,8,9,10}; main(){ int a, b=0; for(a=0;a<10;++a) if(c[a]%2 == 1) b+=c[a]; printf("%d", b);}a)20b)24c)25d)30Correct answer is option 'C'. Can you explain this answer? tests, examples and also practice Class 6 tests.
Explore Courses for Class 6 exam
Signup to solve all Doubts
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev